package security;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

/**
 * The Class SecureRandomNumber generates random numbers to ensure the authenticity of the messages.
 */
public class SecureRandomNumber {

	/**
	 * Generate a random number that will be used once for the communication.
	 * 
	 * @return the string containing the random number generated.
	 */
	public static int generateNonce() {
		try{
			SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
						
			return random.nextInt();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public static byte[] generateSalt(int numBytes){		
		try {
			byte[] _saltBytes = new byte[numBytes];
			 SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
			random.nextBytes(_saltBytes);
			
			return _saltBytes;
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}	      
		
		return null;
	}
}